package org.afun.oldhand.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.afun.oldhand.R;
import org.afun.oldhand.forum.javaBean.MealItemBean;

import java.util.List;

public class MealAdapter extends RecyclerView.Adapter<MealAdapter.MealAdapterViewHolder> {
    private Context mContext;
    private List<MealItemBean> data;


    public MealAdapter(Context mContext, List<MealItemBean> data) {
        this.mContext = mContext;
        this.data = data;
    }

    @NonNull
    @Override
    public MealAdapter.MealAdapterViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view=View.inflate(mContext,R.layout.item_meal,null);
        return new MealAdapter.MealAdapterViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MealAdapter.MealAdapterViewHolder holder, int position) {

        // TODO 数据不绑定方便测试
        holder.mealText1.setText(data.get(position).getMealText1());
//        holder.mealText2.setText(data.get(position).getMealText2());
//        holder.mealText3.setText(data.get(position).getMealText3());
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public class MealAdapterViewHolder extends RecyclerView.ViewHolder {
        private ImageView mealImg;
        private TextView mealText1;
        private TextView mealText2;
        private TextView mealText3;

        public MealAdapterViewHolder(@NonNull View itemView) {
            super(itemView);
            mealImg = itemView.findViewById(R.id.mealImg);
            mealText1 = itemView.findViewById(R.id.mealText1);
            mealText2 = itemView.findViewById(R.id.mealText2);
            mealText3 = itemView.findViewById(R.id.mealText3);
        }
    }
}
